package com.example.designPattern.factory.order;

import com.example.designPattern.factory.pizza.ChinesePizza;
import com.example.designPattern.factory.pizza.GreePizza;
import com.example.designPattern.factory.pizza.Pizza;

import java.io.*;
import java.util.Scanner;

/**
 * pizza订单类
 */
public class OrderPizza {

    private PizzFactory pizzFactory;
    private Pizza pizza;

    public OrderPizza(PizzFactory pizzFactory){
        this.pizzFactory = pizzFactory;
        setFactory();
    }


    public void setFactory(){
        do {
            System.out.printf("请输入需要的pizza名称：");
            String orderType = getType();
            //从工厂里面获取pizza
            pizza = pizzFactory.creatPizza(orderType);
            if (pizza != null){//订购成功
                this.pizza.prepare();
                this.pizza.bake();
                this.pizza.cut();
                this.pizza.box();
            }else {//订购pizza失败
                System.out.println("  订购pizza失败  ");
                break;
            }
        }while (true);
    }


    //读取pizza输入的类型
    private String getType()  {
        try {
            String type ;
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            String s = bufferedReader.readLine();
            return s;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

}
